import time
import numpy as np


class SubSet:
    def __init__(self, dataset, ls):
        self.dataset = dataset
        self.ls = ls

    def __getitem__(self, item):
        return self.dataset[self.ls[item]]

    def __str__(self):
        return str(self.ls)

    def __len__(self):
        return len(self.ls)


def random_split(dataset, target_size, seed=int(time.time())):
    data_length = len(dataset)
    combine_ls = list(range(data_length))  # get the dataset index

    out_ls = []

    np.random.seed(seed)
    for item in target_size:
        x = np.random.choice(combine_ls, size=int(data_length * item), replace=False)
        tuple(map(combine_ls.remove, x))
        out_ls.append(SubSet(dataset, x))
    return out_ls


if __name__ == '__main__':
    x = [i for i in range(100)]
    y = random_split(x, (0.1, 0.2, 0.3, 0.4))
    for i in y:
        print(i)
